<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
     .red {
         color: red;
     }
     .black {
         color: rgb(73, 170, 89)
     }
    </style>
</head>
<body>
    <input type="button" value="点击隔行变色" id="bn">
    <ul id="ulId">
        <li class="">java</li>
        <li class="">C</li>
        <li class="">C++</li>
        <li class="">js</li>
        <li class="">Python</li>
    </ul>
     <script>
        function my$(id) {
            return document.getElementById(id);
        }
        my$("bn").onclick =  function (){
           var liObjets =  my$("ulId").getElementsByTagName("li");
           for (let index = 0; index < liObjets.length; index++) {
                if(index % 2 == 0 ){
                    liObjets[index].className = "red"    
                } else {
                    liObjets[index].className = "black"    
                }
               
           }
        }

     </script>
</body>
</html>